package com.example.im.controller;

import com.example.im.model.Message;
import com.example.im.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    // 查询某个群组的历史消息
    @GetMapping
    public List<Message> getGroupMessages(@RequestParam("groupId") String groupId) {
        return messageService.getMessagesByGroup(groupId);
    }

    // 如果后续要支持查询某个用户相关的消息
    @GetMapping("/user")
    public List<Message> getUserMessages(@RequestParam("fromUser") String fromUser) {
        return messageService.getMessagesByUser(fromUser);
    }
}